#include <iostream>
#include <cstring>

using namespace std;
// #define ONLINE_JUDGE
const int N = 30;

int n;
int w[N];
int f[N][N], root[N][N]; // f[i][j]: 区间[i, j]所有二叉树得分的最大值 root[i][j]: 区间[i, j]构成的二叉树的根节点是谁

void dfs(int l, int r)
{
    if(l > r)   return;

    int u = root[l][r];

    
    printf("%d ", u);
    
    dfs(l, u - 1);
    dfs(u + 1, r);

}

int main() {

    #ifdef ONLINE_JUDGE

    #else
    freopen("./in.txt","r",stdin);
    #endif
    ios::sync_with_stdio(false);
	cin.tie(0);

    cin >> n;   
    for(int i = 1; i <= n; i++)  cin >> w[i]; 

    for(int len = 1; len <= n; len++)
        for(int l = 1, r; (r = l + len - 1) <= n; l++)
        {
            if(len == 1){
                f[l][r] = w[l]; // 叶节点的加分就是本身
                root[l][r] = l;
            }
            else{
                for(int k = l; k <= r; k++) // 枚举[l,r]的分界点
                {
                    int left = k == l ? 1 : f[l][k - 1];
                    int right = k == r ? 1 : f[k + 1][r];
                    int score = left * right + w[k];
                    if(f[l][r] < score)
                    {
                        f[l][r] = score;
                        root[l][r] = k;
                    }
                }
            }

        }

    cout << f[1][n] << endl;
    dfs(1,n);
    cout << endl;

    return 0;
}

